# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=packaging
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=23.1
pkgrel=2
pkgdesc="Core utilities for Python packages (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/pypa/packaging"
license=('Apache' 'BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-flit-core")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest-runner"
              "${MINGW_PACKAGE_PREFIX}-python-pretend"
              "${MINGW_PACKAGE_PREFIX}-python-coverage")
source=(https://pypi.io/packages/source/p/packaging/${_realname}-${pkgver}.tar.gz)
sha256sums=('a392980d2b6cffa644431898be54b0045151319d1e7ec34f0cfed48767dd334f')

prepare() {
  cd "${srcdir}"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m flit_core.wheel
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m pytest
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -d "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}"
  install -Dm644 LICENSE* -t "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}"
}
